function bezier (t, timeFunc, flag) {
    var timeFuncList = {
        "ease": [.25,.1,.25,1],
        "linear":[0,0,1,1],
        "ease-in":[.42,0,1,1],
        "ease-out":[0,0,.58,1],
        "ease-in-out":[.42,0,.58,1]
    };
    var control = [0, 0, 1, 1];
    if(typeof  timeFunc === 'string' && timeFuncList[timeFunc]){
        control = timeFuncList[timeFunc];
    }
    if(typeof timeFunc === 'object' && timeFunc.length === 4){
        control = timeFunc;
    }
    var currentX = 3 * Math.pow(1 - t, 2) * t * control[0] + 3 * (1 - t) * Math.pow(t, 2) * control[2] + Math.pow(t, 3);
    var currentY = flag && 3 * Math.pow(1 - t, 2) * t * control[1] + 3 * (1 - t) * Math.pow(t, 2) * control[3] + Math.pow(t, 3);
    return [currentX, currentY];
}

function animation (dom, start, terminal, prop, duration, timeFunc, callback) {
    var hasNoUnitProps = ['opacity', 'font-weight', 'z-index'];
    var isNoUnit = hasNoUnitProps.indexOf(prop) > -1;
    var timer = null;
    var t = 0;
    timer = setInterval(function () {
        var progress = bezier(t/duration, timeFunc)[0];
        t += 17;
        dom.style[prop] = progress * (terminal - start) + (isNoUnit ? 0 : 'px');
        console.log(progress);
        if(t >= duration) {
            (callback || function () {})();
            clearInterval(timer);
            dom.style[prop] = terminal +  (isNoUnit ? 0 : 'px');
        }
    }, 17);
}

function animationColor (dom, startColor, terminalColor, prop, duration, timeFunc) {
    function color2arr(color) {
        if(/^#([a-f0-9]{3})|([a-f0-9]{6})$/.test(color)){
            if(color.length === 4){
                return color.match(/[a-f0-9]/ig).map(function (value) {
                    return value.repeat(2);
                }).map(function (item) {
                    return parseInt(item, 16);
                })
            }else{
                return color.match(/[a-f0-9]{2}/ig).map(function (value) {
                    return parseInt(value, 16);
                })
            }
        }
        if(/^rgb\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3}\)/.test(color)){
            return color.match(/[0-9]{1,3}/g).map(function (value) {
                if(+value < 0){
                    return 0;
                }else if(+value > 255){
                    return 255;
                }else {
                    return +value;
                }
            })
        }
    }
    var start = color2arr(startColor);
    var terminal = color2arr(terminalColor);
    console.log(start);
    console.log(terminal);
    var timer = null;
    var t = 0;
    timer = setInterval(function () {
        var progress = bezier(t/duration, timeFunc);
        var r = start[0] + (terminal[0] - start[0]) * progress[0];
        var g = start[1] + (terminal[1] - start[1]) * progress[0];
        var b = start[2] + (terminal[2] - start[2]) * progress[0];
        dom.style[prop] = 'rgb('+ r + ',' + g + ',' + b +')';
        console.log(progress);
        t += 17;
        if(t >= duration){
            clearInterval(timer);
            dom.style[prop] = terminalColor;
        }
    }, 17)
}